#include <iostream>
#include <signal.h>
#include <unistd.h>
using namespace std;
void handler(int sig)
{
    cout << "正在处理" << sig << "号信号" << endl;
}
int main()
{
    sigset_t sig, osig;
    sigemptyset(&sig);
    sigaddset(&sig, 2);
    sigaddset(&sig, 40);
    sigprocmask(SIG_SETMASK, &sig, &osig);
    signal(2,handler);
    signal(40,handler);
    cout<<"阻塞2号,40号信号"<<endl;
    cout << "raise 2:" << endl;
    for (int i = 0; i < 5; i++)
    {
        cout<<i+1<<' ';
        fflush(NULL);
        raise(2);
        sleep(1);
    }
    cout<<endl;
    cout << "raise 40:" << endl;
    for (int i = 0; i < 5; i++)
    {
        cout<<i+1<<' ';
        fflush(NULL);
        raise(40);
        sleep(1);
    }
    cout<<endl;
    cout<<"解除阻塞"<<endl;
    sigprocmask(SIG_SETMASK, &osig, nullptr);
    return 0;
}